package com.shenfa.service.xml;

import java.util.*;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.shenfa.bean.xml.*;
import com.shenfa.dao.xml.MakeXmlDao;


public class UserXml {
	@Autowired
	private MakeXmlDao makeXmlDao;
	
	private StringBuffer tab1;
	private StringBuffer tab2;
	private StringBuffer temp;
	private List<StringBuffer> tab2list;
	private List<UserAccinfo> listAccinfo;
	private List<UserAccinfoDetail> listAccinfoDetail;
	private List<Debitinfo> listDebitinfo;
	private List<PointInfo> listPointInfo;
	private List<Foldout> list;
	//模板区域形象
	private List<TempArea> plist;
	
	//自定义区域规则
	private List<RuleF> rlist;
	//默认
	private List<RuleF> dlist;
	//区域规则条件
	private List<RuleM> mlist;
	private List<Rule> rulelist;
	
	private PointInfo point;
	private UserBuy ub;
	
	private Logger log = null;
	
	public UserXml(){
		log = Logger.getLogger(UserXml.class);
	}
	/**
	 * 写入xml
	 * @param px
	 * @param ex
	 * @param city
	 */
	public void writeBaseXml(UserBase ub,StringBuffer xml){
		xml.append("<acctnbr>"+ub.getAcctnbr()+"</acctnbr>\n");
		xml.append("<rectype>"+ub.getRectype()+"</rectype>\n");
		xml.append("<zip>"+ub.getZip()+"</zip>\n");
		xml.append("<addrname3>"+ub.getAddrname3()+" </addrname3>\n");
		xml.append("<addrname1>"+ub.getAddrname1()+" </addrname1>\n");
		xml.append("<addrname2>"+ub.getAddrname2()+" </addrname2>\n");
		xml.append("<name>"+ub.getName()+" </name>\n");
		xml.append("<sex>"+ub.getSex()+"</sex>\n");
		xml.append("<birthday>"+ub.getBirthday()+"</birthday>\n");
		xml.append("<accnum>"+ub.getAccnum()+"</accnum>\n");
		xml.append("<cusnum>"+ub.getCusnum()+"</cusnum>\n");
		xml.append("<stfromdate>"+ub.getStfromdate()+"</stfromdate>\n");
		xml.append("<enddate>"+ub.getEnddate()+"</enddate>\n");
		xml.append("<specode>"+ub.getSpecode()+"</specode>\n");
		xml.append("<pmtduemark>"+ub.getPmtduemark()+"</pmtduemark>\n");
		xml.append("<cashmark>"+ub.getCashmark()+"</cashmark>\n");
		xml.append("<indiv1>"+ub.getIndiv1()+"</indiv1>\n");
		xml.append("<indiv2>"+ub.getIndiv2()+"</indiv2>\n");
		xml.append("<indiv3>"+ub.getIndiv3()+"</indiv3>\n");
		xml.append("<indiv4>"+ub.getIndiv4()+"</indiv4>\n");
		xml.append("<indiv5>"+ub.getIndiv5()+"</indiv5>\n");
		xml.append("<indiv6>"+ub.getIndiv6()+"</indiv6>\n");
		xml.append("<indiv7>"+ub.getIndiv7()+"</indiv7>\n");
		xml.append("<indiv8>"+ub.getIndiv8()+"</indiv8>\n");
		xml.append("<actinfo>"+ub.getActinfo()+"</actinfo>\n");
		xml.append("<dm1>"+ub.getDm1()+"</dm1>\n");
		xml.append("<dm2>"+ub.getDm2()+"</dm2>\n");
		xml.append("<dm3>"+ub.getDm3()+"</dm3>\n");
		xml.append("<dm4>"+ub.getDm4()+"</dm4>\n");
		xml.append("<brandmsg1>"+ub.getBrandmsg1()+"</brandmsg1>\n");
		xml.append("<brandmsg2>"+ub.getBrandmsg2()+"</brandmsg2>\n");
		xml.append("<brandmsg3>"+ub.getBrandmsg3()+"</brandmsg3>\n");
		xml.append("<brandmsg4>"+ub.getBrandmsg4()+"</brandmsg4>\n");
		xml.append("<brandmsg5>"+ub.getBrandmsg5()+"</brandmsg5>\n");
		xml.append("<brandmsg6>"+ub.getBrandmsg6()+"</brandmsg6>\n");
		xml.append("<brandmsg7>"+ub.getBrandmsg7()+"</brandmsg7>\n");
		xml.append("<convexchmark>"+ub.getConvexchmark()+"</convexchmark>\n");
		xml.append("<vipmsg1>"+ub.getVipmsg1()+"</vipmsg1>\n");
		xml.append("<vipmsg2>"+ub.getVipmsg2()+"</vipmsg2>\n");
		xml.append("<vipmsg3>"+ub.getVipmsg3()+"</vipmsg3>\n");
		xml.append("<vipmsg4>"+ub.getVipmsg4()+"</vipmsg4>\n");
		xml.append("<reprintflag>"+ub.getReprintflag()+"</reprintflag>\n");
		xml.append("<emailflag>"+ub.getEmailflag()+"</emailflag>\n");
		xml.append("<paperflag>"+ub.getPaperflag()+"</paperflag>\n");
		xml.append("<emailaddr>"+ub.getEmailaddr()+"</emailaddr>\n");
		xml.append("<custtype>"+ub.getCusttype()+"</custtype>\n");
		xml.append("<mobilenbr>"+ub.getMobilenbr()+"</mobilenbr>\n");
		xml.append("<ainbr>"+ub.getAinbr()+"</ainbr>\n");
		xml.append("<mobdate>"+ub.getMobdate()+"</mobdate>\n");
		xml.append("<filler>"+ub.getFiller()+"</filler>\n");
		xml.append("<citycode>"+ub.getCity()+"</citycode>\n");
	}
	/**
	 * 写入插槽
	 * @param wbs 外包商ID
	 * @param cid 卡产品ID
	 */
	public void writeEnvrule(Map<String,String> map,StringBuffer xml){
		list=makeXmlDao.getFoldout(map);
		String tag="";
		String temp="";
		Foldout f=null;
		if(list.size()>0){
			for(int i=0;i<list.size();i++){
				f=list.get(0);
				temp+="<INPRIORITY"+(i+1)+">"+f.getPri()+"</INPRIORITY"+(i+1)+">\n";
				if(null==f.getName()||"".equals(f.getName())){
					tag+="0";
				}else{
					tag+="1";
				}
			}
		}else{
			tag="0000";
			temp="<INPRIORITY1>0</INPRIORITY1>\n<INPRIORITY2>0</INPRIORITY2>\n<INPRIORITY3>0</INPRIORITY3>\n<INPRIORITY4>0</INPRIORITY4>\n";
		}
		xml.append("<ENVRULE>"+tag+"</ENVRULE>\n");
		xml.append(temp);
	}
	/**
	 * 构造账户汇总信息xml内容
	 * @param ub
	 * @param xml
	 */
	public boolean writeAccinfoXml(UserBase ub,StringBuffer xml){
		tab1=new StringBuffer();
		tab2=new StringBuffer();
		//查询账户汇总信息
		listAccinfo=makeXmlDao.getUserInfo(ub.getAcctnbr());
		//构造xml
		for(UserAccinfo ua:listAccinfo){
			//如果是人民币汇总
			if("B001".equals(ua.getRectype())){
				this.readAccinfo(tab1,ua);
			}//如果是美元汇总
			else if("D001".equals(ua.getRectype())){
				this.readAccinfo(tab2,ua);
			}
		}
		//如果有数据存在
		if(tab1.length()!=0 || tab2.length()!=0){
			xml.append("<accinfo>\n");
			if(tab1.length()>0){
				xml.append("<tab1>\n");
				xml.append(tab1.toString());
				xml.append("</tab1>\n");
			}
			if(tab2.length()>0){
				xml.append("<tab2>\n");
				xml.append(tab2.toString());
				xml.append("</tab2>\n");
			}
			xml.append("</accinfo>\n");
			return false;
		}else{
			return true;
		}
	}
	private void readAccinfo(StringBuffer sb,UserAccinfo ua){
		sb.append("<acctnbr>"+ua.getAcctnbr()+"</acctnbr>\n");
		sb.append("<rectype>"+ua.getRectype()+"</rectype>\n");
		sb.append("<stmtdate>"+ua.getStmtdate()+"</stmtdate>\n");
		sb.append("<pmtdate>"+ua.getPmtdate()+"</pmtdate>\n");
		sb.append("<totbegbal>"+ua.getTotbegbal()+"</totbegbal>\n");
		sb.append("<plantotpmt>"+ua.getPlantotpmt()+"</plantotpmt>\n");
		sb.append("<plantotnrlamt>"+ua.getPlantotnrlamt()+"</plantotnrlamt>\n");
		sb.append("<plantotadjamt>"+ua.getPlantotadjamt()+"</plantotadjamt>\n");
		sb.append("<intdueamt>"+ua.getIntdueamt()+"</intdueamt>\n");
		sb.append("<currbal>"+ua.getCurrbal()+"</currbal>\n");
		sb.append("<totdueamt>"+ua.getTotdueamt()+"</totdueamt>\n");
		sb.append("<pmtprint>"+ua.getPmtprint()+"</pmtprint>\n");
		sb.append("<crlim>"+ua.getCrlim()+"</crlim>\n");
		sb.append("<cashcrlim>"+ua.getCashcrlim()+"</cashcrlim>\n");
		sb.append("<pmtarn>"+ua.getPmtarn()+"</pmtarn>\n");
		sb.append("<pmtadn>"+ua.getPmtadn()+"</pmtadn>\n");
		sb.append("<projap>"+ua.getProjap()+"</projap>\n");
		sb.append("<pmtaflag>"+ua.getPmtaflag()+"</pmtaflag>\n");
		sb.append("<achflag>"+ua.getAchflag()+"</achflag>\n");
		sb.append("<pmtflag>"+ua.getPmtflag()+"</pmtflag>\n");
		sb.append("<filler>"+ua.getFiller()+"</filler>\n");
	}
	/**
	 * 汇总信息明细
	 * @param px
	 * @param ex
	 * @param ub
	 */
	public void writeAccinfoDetail(UserBase ub,StringBuffer xml){
		tab1=new StringBuffer();
		tab2=new StringBuffer();
		listAccinfoDetail=makeXmlDao.getAccinfoDetail(ub.getAcctnbr());
		for(UserAccinfoDetail uad:listAccinfoDetail){
			//如果是人民币
			if("C001".equals(uad.getRectype())){
				this.readAccinfoDetail(tab1,uad);
			}//如果是美元
			else if("E001".equals(uad.getRectype())){
				this.readAccinfoDetail(tab2,uad);
			}
		}
		//如果有数据存在
		if(tab1.length()!=0 || tab2.length()!=0){
			xml.append("<transinfo>\n");
			if(tab1.length()>0){
				xml.append("<tab1>\n<lists>\n");
				xml.append(tab1.toString());
				xml.append("</lists>\n</tab1>\n");
			}
			if(tab2.length()>0){
				xml.append("<tab2>\n<lists>\n");
				xml.append(tab2.toString());
				xml.append("</lists>\n</tab2>\n");
			}
			xml.append("</transinfo>\n");
		}
	}
	
	private void readAccinfoDetail(StringBuffer sb,UserAccinfoDetail uad){
		sb.append("<list>\n");
		sb.append("<acctnbr>"+uad.getAcctnbr()+"</acctnbr>\n");
		sb.append("<rectype>"+uad.getRectype()+"</rectype>\n");
		sb.append("<recseq>"+uad.getRecseq()+"</recseq>\n");
		sb.append("<effdate>"+uad.getEffdate()+"</effdate>\n");
		sb.append("<postdate>"+uad.getPostdate()+"</postdate>\n");
		sb.append("<cardnlast4>"+uad.getCardnlast4()+"</cardnlast4>\n");
		sb.append("<desc>"+uad.getDesc()+"</desc>\n");
		sb.append("<txnamt>"+uad.getTxnamt()+"</txnamt>\n");
		sb.append("<srctamt>"+uad.getSrctamt()+"</srctamt>\n");
		sb.append("<srctcurr>"+uad.getSrctcurr()+"</srctcurr>\n");
		sb.append("<purcty>"+uad.getPurcty()+"</purcty>\n");
		sb.append("<filler>"+uad.getFiller()+"</filler>\n");
		sb.append("</list>\n");
	}
	/**
	 * 购汇信息
	 * @param px
	 * @param ex
	 * @param user
	 */
	public void writeBuy(UserBase user,StringBuffer xml){
		ub=makeXmlDao.getUserBuy(user.getAcctnbr());
		//如果查不到购汇信息
		if(null==ub)return;
		xml.append("<exchinfo>\n");
		xml.append("<acctnbr>"+ub.getAcctnbr()+"</acctnbr>\n");
		xml.append("<rectype>"+ub.getRectype()+"</rectype>\n");
		xml.append("<exchusdamt>"+ub.getExchusdamt()+"</exchusdamt>\n");
		xml.append("<sellrate>"+ub.getSellrate()+"</sellrate>\n");
		xml.append("<exchrmbamt>"+ub.getExchrmbamt()+"</exchrmbamt>\n");
		xml.append("<achrtnbr>"+ub.getAchrtnbr()+"</achrtnbr>\n");
		xml.append("<achdbnbr>"+ub.getAchdbnbr()+"</achdbnbr>\n");
		xml.append("<filler>"+ub.getFiller()+"</filler>\n");
		xml.append("</exchinfo>\n");
	}
	/**
	 * 用户借记卡交易明细
	 * @param px
	 * @param ex
	 * @param user
	 */
	public void writeDebitinfo(UserBase user,StringBuffer xml){
		tab1=new StringBuffer();
		tab2=new StringBuffer();
		listDebitinfo=makeXmlDao.getDebitinfo(user.getAcctnbr());
		for(Debitinfo di:listDebitinfo){
			if("C002".equals(di.getRectype())){
				this.readDebitinfo(tab1,di);
			}else if("E002".equals(di.getRectype())){
				this.readDebitinfo(tab2,di);
			}
		}
		//如果有数据存在
		if(tab1.length()!=0 || tab2.length()!=0){
			xml.append("<debitinfo>\n");
			if(tab1.length()>0){
				xml.append("<tab1>\n<lists>\n");
				xml.append(tab1.toString());
				xml.append("</lists>\n</tab1>\n");
			}
			if(tab2.length()>0){
				xml.append("<tab2>\n<lists>\n");
				xml.append(tab2.toString());
				xml.append("</lists>\n</tab2>\n");
			}
			xml.append("</debitinfo>\n");
		}
	}
	
	private void readDebitinfo(StringBuffer temp,Debitinfo di){
		temp.append("<list>\n");
		temp.append("<acctnbr>"+di.getAcctnbr()+"</acctnbr>\n");
		temp.append("<rectype>"+di.getRectype()+"</rectype>\n");
		temp.append("<custnbr>"+di.getCustnbr()+"</custnbr>\n");
		temp.append("<effdate>"+di.getEffdate()+"</effdate>\n");
		temp.append("<txndesc>"+di.getTxndesc()+"</txndesc>\n");
		temp.append("<txncity>"+di.getTxncity()+"</txncity>\n");
		temp.append("<currcode>"+di.getCurrcode()+"</currcode>\n");
		temp.append("<txnamt>"+di.getTxnamt()+"</txnamt>\n");
		temp.append("<cardl4>"+di.getCardl4()+"</cardl4>\n");
		temp.append("<filler>"+di.getFiller()+"</filler>\n");
		temp.append("</list>\n");
	}
	/**
	 * 积分数据
	 * @param px
	 * @param ex
	 * @param user
	 */
	public void writePoint(UserBase user,StringBuffer xml){
		tab1=new StringBuffer();
		tab2list=new ArrayList<StringBuffer>();
		temp=new StringBuffer();
		//根据ECF客户号码获取携程积分信息
		listPointInfo=makeXmlDao.getPoint(user.getCusnum());
		for(PointInfo pi:listPointInfo){
			//1为普通积分，2为返现积分 
			if("1".equals(pi.getPointtype())){
				this.readPoint(tab1,pi);
			}else if("2".equals(pi.getPointtype())){
				tab2=new StringBuffer();
				this.readPoint(tab2,pi);
				tab2list.add(tab2);
			}
		}
		point=makeXmlDao.getPoint2(user.getCusnum());
		if(null!=point){
			temp.append("<tab3>\n");
			temp.append("<billdate>"+point.getBilldate()+"</billdate>\n");
			temp.append("<ecifno>"+point.getBusinessid()+"</ecifno>\n");
			temp.append("<curpavalia>"+point.getAblepoint()+"</curpavalia>\n");
			temp.append("<pointavabf>"+point.getLastbalpoint()+"</pointavabf>\n");
			temp.append("<newpoint>"+point.getAddpoint()+"</newpoint>\n");
			temp.append("<pointredee>"+point.getExpoint()+"</pointredee>\n");
			temp.append("<adpoints>"+point.getAdpoints()+"</adpoints>\n");
			temp.append("<invalidpoint>"+point.getEndpoints()+"</invalidpoint>\n");
			temp.append("</tab3>\n");
		}

		//如果有数据存在
		if(tab1.length()>0 || tab2list.size()>0 || temp.length()>0){
			xml.append("<point-info>\n");
			if(tab1.length()>0){
				xml.append("<tab1>\n");
				xml.append(tab1.toString());
				xml.append("</tab1>\n");
			}
			if(tab2list.size()>0){
				xml.append("<tab2>\n<lists>\n");
				for(StringBuffer sb:tab2list){
					xml.append("<list>\n"+sb.toString()+"</list>\n");
				}
				xml.append("</lists>\n</tab2>\n");
			}
			if(temp.length()>0){
				xml.append("<tab3>\n");
				xml.append(temp.toString());
				xml.append("</tab3>\n");
			}
			xml.append("</point-info>\n");
		}
	}
	private void readPoint(StringBuffer sb,PointInfo pi){
		if("".equals(pi.getCardportid())){
			sb.append("<pointtype>"+pi.getPointtype()+"</pointtype>\n");
		}
		else{
			if("1".equals(pi.getCardportid())){
				sb.append("<pointtype>A</pointtype>\n");
			}else if("2".equals(pi.getCardportid())){
				sb.append("<pointtype>B</pointtype>\n");
			}
		}
		sb.append("<cardportid>"+pi.getCardportid()+"</cardportid>\n");
		sb.append("<businessid>"+pi.getBusinessid()+"</businessid>\n");
		sb.append("<ablepoint>"+pi.getAblepoint()+"</ablepoint>\n");
		sb.append("<lastbalpoint>"+pi.getLastbalpoint()+"</lastbalpoint>\n");
		sb.append("<addpoint>"+pi.getAddpoint()+"</addpoint>\n");
		sb.append("<expoint>"+pi.getExpoint()+"</expoint>\n");
		sb.append("<adpoints>"+pi.getAdpoints()+"</adpoints>\n");
		sb.append("<endpoints>"+pi.getEndpoints()+"</endpoints>\n");
		sb.append("<ecifno>"+pi.getEcifno()+"</ecifno>\n");
		sb.append("<startdate>"+pi.getStartdate()+"</startdate>\n");
		sb.append("<enddate>"+pi.getEnddate()+"</enddate>\n");
		sb.append("<wholeconsume>"+pi.getWholeconsume()+"</wholeconsume>\n");
		sb.append("<inconsume>"+pi.getInconsume()+"</inconsume>\n");
		sb.append("<outconsume>"+pi.getOutconsume()+"</outconsume>\n");
		sb.append("<wholemoney>"+pi.getWholemoney()+"</wholemoney>\n");
		sb.append("<inmoney>"+pi.getInmoney()+"</inmoney>\n");
		sb.append("<outmoney>"+pi.getOutmoney()+"</outmoney>\n");
		sb.append("<usedmoney>"+pi.getUsedmoney()+"</usedmoney>\n");
		sb.append("<lavemoney>"+pi.getLavemoney()+"</lavemoney>\n");
		sb.append("<validdate>"+pi.getValiddate()+"</validdate>\n");
		sb.append("<laddermoney>"+pi.getLaddermoney()+"</laddermoney>\n");
		sb.append("<ladderscale>"+pi.getLadderscale()+"</ladderscale>\n");
		if("2".equals(pi.getPointtype())){
			sb.append("<card4"+pi.getCard4()+"</card4>\n");
		}
	}
	/**
	 * 模板个性化处理
	 * @param wx  文件流
	 * @param user 用户基本信息
	 * @param cardid 产品ID
	 * @param type 账单类型 1纸质2电子
	 */
	public StringBuffer writeTemplate(UserBase user,String type){
		temp=new StringBuffer();
		Map<String,String> map=new HashMap<String,String>();
		map.put("card",user.getCardNo());
		map.put("temptype",type);
		//获取模板ID
		String ptId=makeXmlDao.getTemplate(map);
		if(null==ptId){
			log.debug("没有匹配的模板信息.卡产品ID="+user.getCardNo()+",类型="+type);
			return new StringBuffer("");
		}
		//模板区域信息
		plist=makeXmlDao.getTemplateInfo(ptId);

		Fodder f=null;
		//是否存在符合条件的规则
		boolean isExtis=false;
		temp.append("<resourcesinfo>\n<lists>\n");
		//遍历模板区域
		for(TempArea ta:plist){
			//获取规则主表信息
			rulelist=makeXmlDao.getRule(ptId,"1",ta.getArea());
			log.debug("规则主表信息.模板ID="+ptId+",区域ID="+ta.getArea()+",规则个数="+rulelist.size());
			//如果有符合的规则
			if(null!=rulelist && rulelist.size()>0){
				//遍历规则
				for(Rule r:rulelist){
					//如果有符合条件的规则跳出此循环
					if(isExtis)break;
					//获取规则详细信息
					rlist=makeXmlDao.getRuleF(r.getRuleid());
					if(null!=rlist){
						//遍历规则详细信息
						for(RuleF rf:rlist){
							//获取素材
							f=makeXmlDao.getFodder(rf.getFodder());
							//如果素材无效，跳过此规则判断
							if(null==f)continue;
							
							//如果是列表类型
							if("3".equals(ta.getType())){
								isExtis=true;//存在符合条件的规则
								readRuleXml(temp,type,ta.getArea(),rf.getPri(),f.getUrl(),f.getLinkurl());
							}
							else{
								//获取规则对应的条件
								mlist=makeXmlDao.getRuleFFList(rf.getId());
								//如果条件判断成立,不需要遍历下一个规则详情
								if(readRule(mlist,user)){
									isExtis=true;//存在符合条件的规则
									//写入xml文件
									readRuleXml(temp,type,ta.getArea(),rf.getPri(),f.getUrl(),f.getLinkurl());
								}
								//如果是自适应类型
								if("4".equals(ta.getType())){
								}else{
									break;//终止该区域的规则判断
								}
							}
						}
					}
				}
			}
			//如果没有符合的规则
			if(!isExtis){
				rulelist=makeXmlDao.getRule(ptId,"0",ta.getArea());
				if(null!=rulelist && rulelist.size()>0){
					//根据规则获取规则信息
					dlist=makeXmlDao.getRuleF(rulelist.get(0).getRuleid());
					if(null!=dlist){
						for(RuleF rf:dlist){
							//获取规则素材
							f=makeXmlDao.getFodder(rf.getFodder());
							//如果素材不可用
							if(null==f){
								log.debug("没有默认规则的素材！模板="+ptId+",区域="+ta.getArea()+",素材="+rf.getFodder());
								continue;
							}
							//写入默认的属性
							readRuleXml(temp,type,ta.getArea(),rf.getPri(),f.getUrl(),f.getLinkurl());
							break;
						}
					}else{
						log.debug("没有默认的规则！模板="+ptId+",区域="+ta.getArea());
					}
				}
			}
			isExtis=false;//重置标志
		}
		temp.append("</lists>\n</resourcesinfo>\n");
		return temp;
	}
	
	public void readRuleXml(StringBuffer xml,String type,String area,String pri,String url,String link){
		xml.append("<list>\n<billtype>");
		xml.append(type);
		xml.append("</billtype>\n<area>");
		xml.append(area);
		xml.append("</area>\n<priority>");
		xml.append(pri);
		xml.append("</priority>\n<rescontent>");
		xml.append(url);
		xml.append("</rescontent>\n<resurl>");
		xml.append(link);
		xml.append("</resurl>\n</list>\n");
	}
	
	/**
	 * 处理规则条件
	 * @param rm
	 * @param user
	 * @return true符合条件，falsh不符合条件
	 */
	public boolean readRule(List<RuleM> list,UserBase user){
		boolean result=false;//返回结果
		boolean oldresult=false;
		int next_if=0;
		String wd="";//维度
		for(RuleM rm:list){
			//获取属性名
			wd=makeXmlDao.getWDInfo().get(rm.getFieldid());
			//如果是生日
			if("birthday".equals(wd)){
				oldresult=checkValue(rm,user.birthday);
			}//如果是性别
			else if("sex".equals(wd)){
				//性别只能是等于，如果是其它的则认为是错误规则
				if(0!=rm.getOpr1()){
					return false;
				}
				//比较取到的值是否一致
				oldresult=rm.getVal1().equals(user.sex);
			}//如果是城市
			else if("city".equals(wd)){
				//城市只能是等于，如果是其它的则认为是错误规则
				if(0!=rm.getOpr1()){
					return false;
				}
				//比较取到的值是否一致
				oldresult=rm.getVal1().equals(user.city);
			}//如果是手机号码
			else if("mobilenbr".equals(wd)){
				//手机号码只能是等于，如果是其它的则认为是错误规则
				if(0!=rm.getOpr1()){
					return false;
				}
				//如果手机号码的前缀存在
				if(0==user.mobilenbr.indexOf(rm.getVal1())){
					oldresult=true;
				}else{
					oldresult=false;
				}
			}//如果是AI码
			else if("ainbr".equals(wd)){
				//AI码只能等于
				if(0!=rm.getOpr1()){
					return false;
				}
				oldresult=rm.getVal1().equals(user.ainbr);
			}//如果是开户日期
			else if("mobdate".equals(wd)){
				oldresult=checkValue(rm,user.mobdate);
			}//如果是固定额度
			else if("crlim".equals(wd)){
				oldresult=checkValue(rm,user.crlim);
			}//如果是本期应付总额
			else if("currbal".equals(wd)){
				oldresult=checkValue(rm,user.currbal);
			}//如果是最低还款额
			else if("totdueamt".equals(wd)){
				oldresult=checkValue(rm,user.totdueamt);
			}//如果是取现额度
			else if("cashcrlim".equals(wd)){
				oldresult=checkValue(rm,user.cashcrlim);
			}
			else if("indiv1".equals(wd)){
				//只能是等于，如果是其它的则认为是错误规则
				if(0!=rm.getOpr1()){
					return false;
				}
				//比较取到的值是否一致
				oldresult=rm.getVal1().equals(user.indiv1);
			}
			else if("indiv2".equals(wd)){
				//只能是等于，如果是其它的则认为是错误规则
				if(0!=rm.getOpr1()){
					return false;
				}
				//比较取到的值是否一致
				oldresult=rm.getVal1().equals(user.indiv2);
			}
			else if("indiv3".equals(wd)){
				//只能是等于，如果是其它的则认为是错误规则
				if(0!=rm.getOpr1()){
					return false;
				}
				//比较取到的值是否一致
				oldresult=rm.getVal1().equals(user.indiv3);
			}
			else if("indiv4".equals(wd)){
				//只能是等于，如果是其它的则认为是错误规则
				if(0!=rm.getOpr1()){
					return false;
				}
				//比较取到的值是否一致
				oldresult=rm.getVal1().equals(user.indiv4);
			}
			else if("indiv5".equals(wd)){
				//只能是等于，如果是其它的则认为是错误规则
				if(0!=rm.getOpr1()){
					return false;
				}
				//比较取到的值是否一致
				oldresult=rm.getVal1().equals(user.indiv5);
			}
			else if("indiv6".equals(wd)){
				//只能是等于，如果是其它的则认为是错误规则
				if(0!=rm.getOpr1()){
					return false;
				}
				//比较取到的值是否一致
				oldresult=rm.getVal1().equals(user.indiv6);
			}
			else if("indiv7".equals(wd)){
				//只能是等于，如果是其它的则认为是错误规则
				if(0!=rm.getOpr1()){
					return false;
				}
				//比较取到的值是否一致
				oldresult=rm.getVal1().equals(user.indiv7);
			}
			else if("indiv8".equals(wd)){
				//只能是等于，如果是其它的则认为是错误规则
				if(0!=rm.getOpr1()){
					return false;
				}
				//比较取到的值是否一致
				oldresult=rm.getVal1().equals(user.indiv8);
			}
			//如果是第一个条件----------------------------------------
			if(0==next_if){
				result=oldresult;
			}//如果是并且判断
			else if(1==next_if){
				result=result&&oldresult;
			}//如果是或者判断
			else if(2==next_if){
				result=result||oldresult;
			}
			//获取逻辑判断
			next_if=rm.getCif();
		}
		return result;
	}

	/**
	 * 常规规则验证
	 * @param rm
	 * @param val
	 * @return
	 */
	private boolean checkValue(RuleM rm,String val){
		boolean result=false;
		boolean result1=false;
		boolean result2=false;
		int i_val=0;
		int i_val1=0;
		int i_val2=0;
		//0:等于1：大于2：小于3：大于等于4：小于等于
		//如果是等于---------------------------------------
		if(0==rm.getOpr1()){
			//比较取到的值是否一致
			result=rm.getVal1().equals(val);
		}//如果不等于0
		else
		{
			//如果转型失败则判断为规则错误
			try{
				i_val=Integer.parseInt(val);
				i_val1=Integer.parseInt(rm.getVal1());
				i_val2=Integer.parseInt(rm.getVal2());
			}catch(Exception e){
				return false;
			}
			//判断条件1-----------------------------------
			if(1==rm.getOpr1()){
				result1=i_val>i_val1;
			}else if(2==rm.getOpr1()){
				result1=i_val<i_val1;
			}else if(3==rm.getOpr1()){
				result1=i_val>=i_val1;
			}else if(4==rm.getOpr1()){
				result1=i_val<=i_val1;
			}
			//判断条件2------------------------------------
			if(1==rm.getOpr2()){
				result2=i_val>i_val2;
			}else if(2==rm.getOpr2()){
				result2=i_val<i_val2;
			}else if(3==rm.getOpr2()){
				result2=i_val>=i_val2;
			}else if(4==rm.getOpr2()){
				result2=i_val>=i_val2;
			}
			result=result1 && result2;
		}
		return result;
	}
}
